package com.shujia.sql

import org.apache.flink.table.api.{EnvironmentSettings, TableEnvironment}

object Demo6DataGen {
  def main(args: Array[String]): Unit = {

    val setting: EnvironmentSettings = EnvironmentSettings
      .newInstance()
      .inStreamingMode()
      .build()

    val table: TableEnvironment = TableEnvironment.create(setting)

    /**
      *
      * datagen: 用于随机生成测试数据
      */

    table.executeSql(
      """
        |CREATE TABLE datagen_source (
        | id INT,
        | name STRING,
        | age INT,
        | gender STRING,
        | clazz STRING
        |) WITH (
        | 'connector' = 'datagen',
        | 'rows-per-second'='5'
        |)
        |
      """.stripMargin)


    table.executeSql(
      """
        |CREATE TABLE print_table
        |WITH ('connector' = 'print')
        |LIKE datagen_source (EXCLUDING ALL)
        |
      """.stripMargin)

    table.executeSql(
      """
        |insert into print_table
        |select * from datagen_source
      """.stripMargin)

  }

}
